package com.ydd.controller.admin;

import com.ydd.dto.SysUserDTO;
import com.ydd.dto.SysUserPageQueryDTO;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.SysUserService;
import com.ydd.vo.SysUserRowInfoVO;
import com.ydd.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "管理员管理")
@RequestMapping("/sys_user")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户列表分页
     */
    @ApiOperation("用户列表分页")
    @GetMapping("/list")
    public Result<PageResult> sysUserList(SysUserPageQueryDTO sysUserPageQueryDTO){

        log.info("用户列表分页: {}", sysUserPageQueryDTO);

        // 返回用户列表分页数据
        PageResult pageResult = sysUserService.pageQueryList(sysUserPageQueryDTO);

        return Result.success(pageResult);
    }


    /**
     * 管理员添加
     * @param sysUserDTO
     * @return
     */
    @ApiOperation("管理员添加")
    @PostMapping("/add")
    public Result sysUserAdd(@RequestBody SysUserDTO sysUserDTO){
        log.info("管理员添加");
        sysUserService.addSysUser(sysUserDTO);
        return Result.success();
    }

    /**
     * 管理员删除
     * @return
     */
    @ApiOperation("管理员删除")
    @GetMapping("/del")
    public Result sysUserDelete(String id){
        log.info("管理员删除: {}", id);
        sysUserService.sysUserDelete(id);
        return Result.success();
    }

    /**
     * 管理员详情
     * @return
     */
    @ApiOperation("管理员详情")
    @GetMapping("/rowInfo")
    public Result<SysUserRowInfoVO> getById(String id){
        log.info("管理员详情: {}", id);
        SysUserRowInfoVO sysUserRowInfoVO = sysUserService.getById(id);
        return Result.success(sysUserRowInfoVO);
    }

    @ApiOperation("管理员修改")
    @PostMapping("/update")
    public Result updateSysUser(@RequestBody SysUserDTO sysUserDTO){
        log.info("管理员修改: {}", sysUserDTO);
        sysUserService.update(sysUserDTO);
        return Result.success();
    }
}
